#!/bin/bash

repo list |awk -F ":" '{print $1}' > /tmp/repo_list
while  read   i
do
	pushd $i 1>/dev/null
	commit=`git rev-parse HEAD`
	popd 1>/dev/null
	matched_line=`grep ''path=\"$i\"'' .repo/manifests/* -r -n  |wc -l `
	if [ $matched_line -ne 1 ];then
		echo "$i" matched lines below:
		grep ''path=\"$i\"'' .repo/manifests/* -r -n  
		exit 
	fi
	
	grep ''path=\"$i\"'' .repo/manifests/* -r -n |grep "remote=\"openfde\""
	if [ $? = 0 ];then
		continue
	fi
	file=`grep ''path=\"$i\"'' .repo/manifests/* -r -n |awk -F ":" '{print $1}'` 
	line=`grep ''path=\"$i\"'' .repo/manifests/* -r -n |awk -F ":" '{print $2}'` 
	sed -i "$line s/revision=.* //" $file
	sed -i "$line s/revision=.*\/>/\/>/" $file
	sed -i "$line s/\/>/revision=\"$commit\"\/>/" $file

done < /tmp/repo_list
